package com.bdqn.controller;

import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;

/**
 * ExampleController
 *
 * @author LILIBO
 * @since 2023-12-15
 */
@Controller
public class ExampleController {

    @Resource
    private UserService userService;

    @GetMapping("/hello/{id}")
    public String hello(Model model, @PathVariable("id") Long usrId) {
        User user = userService.getById(usrId);
        model.addAttribute("user", user);

        List<User> list = userService.list();
        model.addAttribute("users", list);

        model.addAttribute("userName", "ktjiaoyu");
        model.addAttribute("test", "model");
        model.addAttribute("test1", "model1");
        model.addAttribute("date", new Date());
        model.addAttribute("flag", "yes");
        return "demo/hello"; // 匹配 templates/demo.html/hello.html 模板文件
    }

    @GetMapping("/demo")
    public String demo() {
        return "demo/layout/demo";
    }

    @GetMapping("/index")
    public String index() {
        return "demo/index";
    }


    @GetMapping("/test")
    public String test() {
        return "demo/test";
    }

}
